<?php
$project = elgg_extract ( 'entity', $vars, FALSE );

$name_label = elgg_echo ( 'submana:addprojects:name' );
$name_input = elgg_view ( 'input/text', array (
		'name' => 'name',
		'value' => $project->title 
) );
$max_group_label = elgg_echo ( 'submana:addprojects:maxgroup' );
$max_group_input = elgg_view ( 'input/text', array (
		'name' => 'max_group',
		'value' => $project->max_group 
) );

$max_student_label = elgg_echo('Số sinh viên tối đa/nhóm');
$min_student_label = elgg_echo('Số sinh viên tối tối thiểu/nhóm');

$project_guid = elgg_view ( 'input/hidden', array (
		'name' => "project_guid",
		'value' => $vars ['project_guid'] 
) );

$group_guid = elgg_view ( 'input/hidden', array (
		'name' => "group_guid",
		'value' => $vars ['group_guid'] 
) );

$descp_label = elgg_echo ( 'Mô tả đề tài' );
$descp_input = elgg_view ( 'input/plaintext', array (
		'name' => 'descp',
		'class' => "required",
		'value' => $project->description,
) );

// add deadline form
$deadline_label = elgg_echo ( 'submana:deadline' );
$deadline_input = elgg_view ( 'input/date', array (
		'name' => 'deadline',
		'class' => "required",
		'value' => $project->deadline,
) );

$save_button = elgg_view ( 'input/submit', array (
		'value' => elgg_echo ( 'submana:addprojects:save' ) 
) );
$reset_button = elgg_view ( 'input/reset', array (
		'value' => elgg_echo ( 'submana:addprojects:reset' ) 
) );

//--------- Edit group memeber ---------------------
if ($project->approved) {
	$next_button = elgg_view ( 'input/button', array (
			'name' => 'action',
			'value' => elgg_echo ( 'submana:projects:addmember' ),
			'class' => 'elgg-button-action',
			'onclick' => "addmember()"
	) );
	
	
	
	$members_label = elgg_echo ( 'submana:project:members' );
	$edit_groupmemember = "<label for='members'>$members_label</label>";
	$edit_groupmemember .= "<div style='width: 50%; margin: 20px;'>";
	$edit_groupmemember .= "<div id='project_memeber'>";
	$i = 0;
	
	foreach ( $project->students as $student_guid ) {
		$student = get_user_by_username ( $student_guid );
		
		if ($student) {
			$member_input = elgg_view ( 'input/text', array (
					'name' => "member" . ($i +1),
					'id' => 'project_member'.($i + 1),
					'value' => $student->username,
			) );
			$edit_groupmemember.=$member_input;
			$i++;
		}
	}
	$edit_groupmemember .= "</div>";
	$edit_groupmemember.=$next_button;
	$edit_groupmemember .= "</div>";
	
	$members = elgg_view ( 'input/hidden', array (
			'name' => 'total_member',
			'id' => "total_member",
			'value' =>$i,
	) );
}

echo <<<___HTML
<div style="width:80%;">
	<label>$name_label</label>
	$name_input
</div>
<div style="width:80%;">
	<label>$descp_label</label>
	$descp_input
</div>
<div class="left" style="width:40%;">
	<label>$deadline_label</label>
	$deadline_input
</div>
<div class="clearboth"></div>
<div style="width:50%;">
	<label>$max_group_label</label>
	$max_group_input
</div>
<div style = "width:40%;">
	<label for="dealine">$max_student_label</label>
	<input type="number" value='$project->max_student' name="max_student" min="1">
</div>
<div style = "width:40%;">
	<label for="dealine">$min_student_label</label>
	<input type="number" value='$project->min_student' name="min_student" min="1">
</div>
<div>
	$edit_groupmemember
</div>
<div>
	$members
	$project_guid
	$group_guid
	$save_button
	$reset_button
</div>
___HTML;

?>


<style>
<!--
-->
</style>

<script type="text/javascript">
<!--
var member = <?php echo $i;?>;
function addmember(){
	member++;
	var strHTML = '<div>'+
				  '<input type="text" value="" name="member'+member+'" '+
				  'id="project_member'+member+'" class="elgg-input-text">'+
				  '</div>';
	$('#project_memeber').append(strHTML);
	$('#total_member').val(member);
}
//-->
</script>

